package com.welson.db.cryptor.wrapper;

import com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.welson.db.cryptor.util.EncryptHandler;

import java.util.Collection;

/**
 * 加密包装器基类
 * @author welson
 * @param <T> 实体类型
 * @param <R> 当前包装器类型
 * @param <Children> 子类类型
 */
public abstract class AbstractEncryptLambdaWrapper<T, Children extends AbstractEncryptLambdaWrapper<T, Children>>
        extends AbstractLambdaWrapper<T, Children> {
    
    /**
     * 加密字段的等值查询
     */
    public Children encryptEq(SFunction<T, ?> column, Object val) {
        return eq(column, EncryptHandler.encrypt(val));
    }

    public Children encryptNe(SFunction<T, ?> column, Object val) {
        return ne(column, EncryptHandler.encrypt(val));
    }

    /**
     * 加密字段的IN查询
     */
    public Children encryptIn(SFunction<T, ?> column, Collection<?> coll) {
        return in(column, EncryptHandler.encryptCollection(coll));
    }

    public Children encryptNotIn(SFunction<T, ?> column, Collection<?> coll) {
        return notIn(column, EncryptHandler.encryptCollection(coll));
    }
}